package com.goktech.olala.core.service.impl;

import com.goktech.olala.core.service.IRegisterService;
import com.goktech.olala.server.dao.customer.CustomerMapper;
import com.goktech.olala.server.dao.customer.LoginMapper;
import com.goktech.olala.server.pojo.customer.Customer;
import com.goktech.olala.server.pojo.customer.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname RegisterServiceImp
 * @Description TODO
 * @Date 2020/12/10 9:45
 * @Created by sanming
 */
@Service
public class RegisterServiceImp implements IRegisterService {

    @Autowired
    LoginMapper loginMapper;

    @Autowired
    CustomerMapper customerMapper;

    @Override
    public int insert(Login record) {
        Login login = this.selectRegister(record.getLoginName());
        if (login == null){
            loginMapper.insert(record);
            customerMapper.insertCustomerInfId(record.getCustomerId(),record.getLoginName());
            return 2;
        }else{
            return 1;
        }
    }

    @Override
    public List<Login> selectAll() {
        return loginMapper.selectAll();
    }

    @Override
    public Login selectUserAndPassword(String userName, String password) {
        return loginMapper.selectUserAndPassword(userName,password);
    }

    @Override
    public Login selectRegister(String email) {
        return loginMapper.selectRegister(email);
    }

    @Override
    public Customer selectEmail(String email) {
        return customerMapper.selectEmail(email);
    }

    @Override
    public int updateByPrimaryKey(Customer record) {
        return customerMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateEmail(String email, String loginName) {
        return loginMapper.updateEmail(email,loginName);
    }

}
